/**
 * 全局文件配置
 */
import Vue from 'vue';
import VueRouter from 'vue-router';
import 'font-awesome/css/font-awesome.min.css';
import ElementUI, { Notification } from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './styles/style.scss';
import './assets/fonts/fonts.css'; // 引入字体文件
import './assets/icon';
import App from './App';
import imageViewer from './assets/imageViewer';
import './utils/BtnPermissions';
import './utils/maxHeight';
import utils from './utils/utils';
import hooks from './utils/hooks';
import filters from './utils/filter';
import options from './constants/options';
import store from './store';
import router from './router';
import prompt from './components/promptMessage.js';
import VideoPlayer from 'vue-video-player';
import './permission'; // permission control，单独建立permission文件时，一定要引入
import Meta from 'vue-meta';
import vueEsign from 'vue-esign';
import Viewer from 'v-viewer';
import 'viewerjs/dist/viewer.css';
import './initComponents';
import lodash from 'lodash-es';
import maxnum from './utils/directives/maxnum';
import globalComponents from './components/globalComponents';
import customDirectives from './utils/directives';
import 'vue-video-player/src/custom-theme.css';
import 'video.js/dist/video-js.css';
import BaiduMap from 'vue-baidu-map';
import socketInstance from './utils/socket';
import clipboard from 'clipboard'



// 实现语音播报 ----------------------------------------------------------------------
import * as voicePromptFun from './constants/playAudio';
import { msgCancelOrder, msgNewOrder } from './constants/playAudio';

// Vue.prototype.socket = io(`${process.env.SOCKET_URL}?token=kG8qA6qG1aP5aR3g`;

ElementUI.Select.computed.readonly = function () {
  // trade-off for IE input readonly problem: https://github.com/ElemeFE/element/issues/10403
  const isIE = !this.$isServer && !Number.isNaN(Number(document.documentMode));

  return !(this.filterable || this.multiple || !isIE) && !this.visible;
};

Vue.prototype.$lodash = lodash;
Vue.prototype.clipboard = clipboard;
// require('./mock.js')
// 注册插件
Vue.use(ElementUI);
Vue.use(VueRouter);
Vue.use(utils);
Vue.use(filters);
Vue.use(options);
Vue.use(hooks);
Vue.use(imageViewer);
Vue.use(prompt);
Vue.use(VideoPlayer);
Vue.use(Meta);
Vue.use(vueEsign); // 电子签名
Vue.use(Viewer); // 图片预览
// Vue.use(maxnum)
Vue.use(customDirectives); // 注册全局指令
Vue.use(globalComponents);
Vue.use(BaiduMap, {
  ak: process.env.VITE_BAIDU_AK,
});
Viewer.setDefaults({
  Options: {
    inline: true,
    button: true,
    navbar: true,
    title: true,
    toolbar: true,
    tooltip: true,
    movable: true,
    zoomable: true,
    rotatable: true,
    scalable: true,
    transition: true,
    fullscreen: true,
    keyboard: true,
    url: 'data-source',
  },
});

Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  render: (h) => h(App),
  sockets: {
    connecting() {
      console.log('正在连接');
    },
    connect() {
      console.log('连接成功');
    },
    disconnect() {
      const userInfo_id = store.getters.userId;
      socketInstance.emit('refresh', userInfo_id);
      console.log('断开连接');
    },
    connect_failed() {
      console.log('连接失败');
    },
    error() {
      console.log('错误发生，并且无法被其他事件类型所处理');
    },
    reconnecting() {
      console.log('正在重连');
    },
    reconnect_failed() {
      console.log('重连失败');
    },
    reconnect() {
      console.log('重连成功');
    },
    message: (data) => {
      console.log('message', data);
      const msg = data.msg;
      const source = data.source;
      // source = 1系统消息 10呼叫 20取消
      if (source === 30) return;
      switch (source) {
        // 呼叫
        case 10:
          Notification.info({
            title: msg,
            message: '点击处理',
            onClick: function () {
              router.push({ path: '/order/orderManagement' });
              Notification.closeAll();
            },
            duration: 30000,
          });
          voicePromptFun.msgNewOrder();
          break;
        // 取消
        case 20:
          Notification.info({
            title: msg,
            onClick: function () {
              Notification.closeAll();
            },
            duration: 30000,
          });
          voicePromptFun.msgCancelOrder();
          break;
        default:
          Notification.info({
            title: msg,
            onClick: function () {
              Notification.closeAll();
            },
            duration: 3000,
          });
          voicePromptFun.msgDingdong();
          break;
      }
    },
  },
  router,
  store,
  components: { App },
}).$mount('#app');
